/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.QueryGroup;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdFluidModelBo;
import com.comac.ins.isfd.domain.bo.IsfdModelBo;
import com.comac.ins.isfd.domain.vo.IsfdFluidModelVo;
import com.comac.ins.isfd.service.IsfdFluidModelService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * 流体库管理
 *
 * 123
 * @date 2024-7-1
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fluid/model")
public class IsfdFluidModelController extends BaseController {

    @Autowired
    private IsfdFluidModelService IIsfdModelService;

    /**
     * 流体库分页列表查询
     */
    @SaCheckPermission("isfd:fluid:list")
    @GetMapping("/list")
    public TableDataInfo<IsfdFluidModelVo> list(@Validated(QueryGroup.class) IsfdFluidModelBo bo, PageQuery pageQuery) {
        return IIsfdModelService.queryPageList(bo, pageQuery);
    }

    /**
     * 流体库新增保存
     */
    @SaCheckPermission("isfd:fluid:save")
    @Log(title = "上传model + 详细信息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<Void> save(@RequestParam("file") MultipartFile file, @RequestParam("name") String modelName,
                        @RequestParam("desity") String desity,
                        @RequestParam("pressure") String pressure,
                        @RequestParam("temperature") String temperature,
                        @RequestParam("specificHeatCapacity") String specificHeatCapacity,
                        @RequestParam("specificHeatRatio") String specificHeatRatio,
                        @RequestParam("internalEnergy") String internalEnergy,
                        @RequestParam("gasConstant") String gasConstant,
                        @RequestParam("viscosity") String viscosity,
                        @RequestParam("thermalConductivity") String thermalConductivity,
                        @RequestParam("massDiffusivity") String massDiffusivity,
                        @RequestParam("saturationPressure") String saturationPressure,
                        @RequestParam("saturationTemperature") String saturationTemperature,
                        @RequestParam("latentHeat") String latentHeat,
                        @RequestParam("surfaceTension") String surfaceTension) {
        IsfdFluidModelBo isfdModelBo = new IsfdFluidModelBo();
        isfdModelBo.setName(modelName);
        isfdModelBo.setDesity(desity);
        isfdModelBo.setPressure(pressure);
        isfdModelBo.setTemperature(temperature);
        isfdModelBo.setSpecificHeatCapacity(specificHeatCapacity);
        isfdModelBo.setSpecificHeatRatio(specificHeatRatio);
        isfdModelBo.setInternalEnergy(internalEnergy);
        isfdModelBo.setGasConstant(gasConstant);
        isfdModelBo.setViscosity(viscosity);
        isfdModelBo.setThermalConductivity(thermalConductivity);
        isfdModelBo.setMassDiffusivity(massDiffusivity);
        isfdModelBo.setSaturationPressure(saturationPressure);
        isfdModelBo.setSaturationTemperature(saturationTemperature);
        isfdModelBo.setLatentHeat(latentHeat);
        isfdModelBo.setSurfaceTension(surfaceTension);
        // 调用服务层保存文件和模型信息
        return toAjax(IIsfdModelService.save(file, isfdModelBo));
    }
    /**
     * 删除流体库对象
     *
     * @param modelId 流体库id数组
     */
    @SaCheckPermission("isfd:fluid:remove")
    @Log(title = "流体库删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{modelId}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String modelId) {
        return toAjax(IIsfdModelService.deleteWithValidByIds(modelId, true));
    }

    /**
     * 下载文件
     *
     * @param modelId 模型库id
     */
    @SaCheckPermission("isfd:fluid:download")
    @GetMapping("/download/{modelId}")
    public void download(@PathVariable String modelId, HttpServletResponse response) throws IOException {
        IIsfdModelService.download(modelId, response);
    }

}
